;(function(){
  'use strict';
  /**
   * customer 吴尧
   * @ngdoc function
   * @name sasdApp.controller:customerAnalysisController
   * @description 物联网业务量统计分析
   * # customerAnalysisController
   * Controller of the sasApp
   */
  angular.module('controllers.pbossSysBusiness.pbossSysBusinessStastic',[])
    .controller('pbossBusinessStatisticCtrl', pbossBusinessStatisticCtrl);

  function pbossBusinessStatisticCtrl($scope,sysBusinessStatisticFactory,sumBusinessStatisticService,CoreService,$filter,$timeout,COREDATA,CoreLoading) {
    $scope.errorInfo = COREDATA.ERRORINFO;   //日期错误信息
    $scope.provinces = COREDATA.PROVINCES;
    $scope.initQuery = function(){
      sysBusinessStatisticFactory.queryBusinessName(function(res){
        $scope.shoumun = 1;
        $scope.businessList = res.data;
        $scope.queryData();
      });
    };
    $scope.translate ={
      provinceCodes:[],
      searchTime: new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1),
      businessCode:'BIP2B958',
    };
    var paramsData = {};
    var searchTime;
    var businessName;
    var pbossEcharts = echarts.init(document.getElementById('pbossStatistic'));
    $scope.queryData = function(){
      $scope.shoumun==1?$scope.shoumun=0:$scope.shoumun=1;
      if($scope.shoumun === 0){
        CoreLoading.setState(true);
        angular.forEach($scope.businessList, function(item){
          if($scope.translate.businessCode === item.businessCode){
            businessName = item.businessName;
          }
        });

        $scope.send = {
          provinceCodes : [],
          searchTime : CoreService.dateFormat($scope.translate.searchTime, 'yyyyMMdd'),
          businessCode : $scope.translate.businessCode
        };
        angular.forEach($scope.translate.provinceCodes,function(pro){
          $scope.send.provinceCodes.push(pro.provinceCode);
        });
        sumBusinessStatisticService.querySumBusinessStatistic($scope.send,function(res){
          if(res.state === '10000' && res.data.length >= 1){
            $scope.items = res.data;
            var hours = [];
            var statistical = [];
            angular.forEach(res.data,function(item){
              hours.push(item.hours);
              statistical.push(item.statistical);
            });
            searchTime = $filter('date')($scope.translate.searchTime,'yyyyMMdd');
              var itemStyle =  {
                normal: { // 系列级个性化，横向渐变填充
                  borderRadius: 5,
                  label: {
                    show: true,
                    textStyle: {
                      fontSize: '10',
                      fontFamily: '微软雅黑',
                      fontWeight: 'bold'
                    }
                  }
                }
              };
              var option = {
                title: {
                  text: businessName+'业务成交量分时刻统计_'+searchTime,
                  x: 'center'
                },
                tooltip: {
                  trigger: 'axis',
                  axisPointer: {
                    type: 'shadow'
                  }
                },
                legend: {
                  orient: 'vertical',
                  x: 'right',
                  y: 'center',
                  data: ['物联网']
                },
                grid: {
                  x2: '8%'
                },
                xAxis: [
                  {
                    type: 'category',
                    data: hours
                  }
                ],
                yAxis: [
                  {
                    type: 'value' ,
                    // boundaryGap: [0, 0.1]
                  }
                ],
                series: [
                  {
                    name: '物联网',
                    type: 'bar',
                    itemStyle: itemStyle,
                    data: statistical
                  }
                ]
              };

            $timeout(function(){
              $scope.flagObj = true;
              CoreLoading.setState(false);
                pbossEcharts.setOption(option);
            }, 1000);

         }else if(res.data.length === 0){
            CoreService.dialog('查询无数据');
        }else {
            CoreService.dialog('查询错误');
        }
        CoreLoading.setState(false);
        });
      }
    };
    $scope.queryData();
  }
})();

